<?php

if ( ! defined("IN_OP") )
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'] , 1 , $gametype);
$chk->checkShow3dPage();
if ( $g_gametype_3d[$gametype]['type'] == 3 && $g_gametype_3d[$gametype]['en'] != "5h" )
{
    $Show8NFlag = true;
}
else
{
    $Show8NFlag = false;
}

if ( $chk->show3D3S == 3 )
{
    $Show5NFlag = false;
}
else if ( $chk->show3D3S == 2 )
{
    $Show5NFlag = true;
}
else if ( $chk->show3D3S == 1 )
{
    $Show5NFlag = getShow35($gametype);
}
else
{
    exit("error show3D3S");
}
unset($chk);
if ( SubAccountRight($curruser , 3) != 2 )
{
    exit("error right!");
}
$chkGametype = chkGametype($gametype);
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
$jsCode = "";
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
if ( $conf->get("calcbet_{$tbl}") == "1" )
{
    $ui->showErrorPage("{$tblName}颁奖过帐中，请稍後再使用本功能！");
    exit();
}
if ( $conf->get("cnyDateS") == "" || $conf->get("cnyDateE") == "" )
{
    $ui->showErrorPage("请先至[系统]页面设定[春节休市期间]後再使用本功能！");
    exit();
}
include_once( "class/function_3d.php" );
if ( $chkGametype == 3 )
{
    include_once( "class_5h/MyLotto_5h.php" );
    $MyLotto_3d = new MyLotto_5h($gametype);
}
elseif ( $chkGametype == 4 )
{
    include_once( "class_sb/MyLotto_sb.php" );
    $MyLotto_3d = new MyLotto_sb($gametype);
}
else
{
    include_once( "class_3d/MyLotto_3d.php" );
    if ( $Show5NFlag )
    {
        $MyLotto_3d = new MyLotto_3d_5n($gametype);
    }
    else
    {
        $MyLotto_3d = new MyLotto_3d($gametype);
    }
}
$cmd = getvar("cmd");
$id = intval(getvar("id"));
$idstr = $id == ""?"":"&id=".$id;
$editAgainFlag = false;
if ( ispost() )
{
    $cnyDateSInt = strtotime($conf->get("cnyDateS")." 00:00:00");
    $cnyDateEInt = strtotime($conf->get("cnyDateE")." 23:59:59");
    $addOnlyNowRound = intval(getvar("addOnlyNowRound"));
    $reUrl = "op.php?op=admin&fp=lotto_3s&gametype={$gametype}&cmd=".$cmd.$idstr;
    $open = $_POST['open'];
    $roundArr = $_POST['round'];
    if ( $gametype == 24 )
    {
        $n10Arr = $_POST['n1'];
        $n9Arr = $_POST['n2'];
        $n8Arr = $_POST['n3'];
        $n7Arr = $_POST['n4'];
        $n6Arr = $_POST['n5'];
        $n5Arr = $_POST['n6'];
        $n4Arr = $_POST['n7'];
        $n3Arr = $_POST['n8'];
        $n2Arr = $_POST['n9'];
        $n1Arr = $_POST['n10'];
    }
	else if ( $chkGametype == 4 )
	{
		$n3Arr = $_POST['n3'];
		$n2Arr = $_POST['n2'];
		$n1Arr = $_POST['n1'];	
	}
    else
    {
        if ( $Show8NFlag )
        {
            $n8Arr = $_POST['n1'];
            $n7Arr = $_POST['n2'];
            $n6Arr = $_POST['n3'];
            $n5Arr = $_POST['n4'];
            $n4Arr = $_POST['n5'];
            $n3Arr = $_POST['n6'];
            $n2Arr = $_POST['n7'];
            $n1Arr = $_POST['n8'];
        }
        else
        {
            if ( $chkGametype == 3 )
            {
                $n5Arr = $_POST['n1'];
                $n4Arr = $_POST['n2'];
                $n3Arr = $_POST['n3'];
                $n2Arr = $_POST['n4'];
                $n1Arr = $_POST['n5'];
            }
            else
            {
                if ( $Show5NFlag )
                {
                    $n5Arr = $_POST['n5'];
                    $n4Arr = $_POST['n4'];
                }
                $n3Arr = $_POST['n3'];
                $n2Arr = $_POST['n2'];
                $n1Arr = $_POST['n1'];
            }
        }
    }
    $openbetArr = $_POST['openbet'];
    $startbetHoursArr = $_POST['startbetHours'];
    $stopbetHoursArr = $_POST['stopbetHours'];
    $openbetHoursArr = $_POST['openbetHours'];
    $startbetMinArr = $_POST['startbetMin'];
    $stopbetMinArr = $_POST['stopbetMin'];
    $openbetMinArr = $_POST['openbetMin'];
    if ( $open == "0000-00-00" )
    {
        
    }
    else if ( ! is_date($open) )
    {
        diemsg("{$tblName}报表日期格式不正确" , $reUrl);
    }
    foreach ( $roundArr as $key => $roundVal )
    {
        if ( $roundVal == "" )
        {
            continue;
        }
        $round = trim($roundVal);
        $n1 = $n1Arr[$key];
        $n2 = $n2Arr[$key];
        $n3 = $n3Arr[$key];
        $n6 = 0 - 1;
        $n7 = 0 - 1;
        $n8 = 0 - 1;
        $n9 = 0 - 1;
        $n10 = 0 - 1;
        if ( $gametype == 24 )
        {
            $n9 = $n9Arr[$key];
            $n10 = $n10Arr[$key];
        }
        if ( $Show8NFlag )
        {
            $n4 = $n4Arr[$key];
            $n5 = $n5Arr[$key];
            $n6 = $n6Arr[$key];
            $n7 = $n7Arr[$key];
            $n8 = $n8Arr[$key];
        }
        else if ( $Show5NFlag )
        {
            $n4 = $n4Arr[$key];
            $n5 = $n5Arr[$key];
        }
        else
        {
            $n4 = 0 - 1;
            $n5 = 0 - 1;
        }
        $openbet = $openbetArr[$key];
        $startbetHours = $startbetHoursArr[$key];
        $stopbetHours = $stopbetHoursArr[$key];
        $openbetHours = $openbetHoursArr[$key];
        $startbetMin = $startbetMinArr[$key];
        $stopbetMin = $stopbetMinArr[$key];
        $openbetMin = $openbetMinArr[$key];
        if ( $openbet == "0000-00-00" )
        {
            
        }
        else
        {
            if ( ! is_date($openbet) )
            {
                continue;
            }
            if ( ! $MyLotto_3d->checkNum($n3) )
            {
                diemsg("{$tblName}资料输入错误" , "n3开奖号码错误" , $reUrl);
            }
            else if ( ! $MyLotto_3d->checkNum($n2) )
            {
                diemsg("{$tblName}资料输入错误" , "n2开奖号码错误" , $reUrl);
            }
            else if ( ! $MyLotto_3d->checkNum($n1) )
            {
                diemsg("{$tblName}资料输入错误" , "n1开奖号码错误" , $reUrl);
            }
            else if ( $Show5NFlag && ! $MyLotto_3d->checkNum($n4) )
            {
                diemsg("{$tblName}资料输入错误" , "n4开奖号码错误" , $reUrl);
            }
            else if ( $Show5NFlag && ! $MyLotto_3d->checkNum($n5) )
            {
                diemsg("{$tblName}资料输入错误" , "n5开奖号码错误" , $reUrl);
            }
            else if ( $Show8NFlag && ! $MyLotto_3d->checkNum($n6) )
            {
                diemsg("{$tblName}资料输入错误" , "n6开奖号码错误" , $reUrl);
            }
            else if ( $Show8NFlag && ! $MyLotto_3d->checkNum($n7) )
            {
                diemsg("{$tblName}资料输入错误" , "n7开奖号码错误" , $reUrl);
            }
            else if ( $Show8NFlag && ! $MyLotto_3d->checkNum($n8) )
            {
                diemsg("{$tblName}资料输入错误" , "n8开奖号码错误" , $reUrl);
            }
        }
        $n1 = $n1 === ""?"-1":intval($n1);
        $n2 = $n2 === ""?"-1":intval($n2);
        $n3 = $n3 === ""?"-1":intval($n3);
        $n4 = $n4 === ""?"-1":intval($n4);
        $n5 = $n5 === ""?"-1":intval($n5);
        $n6 = $n6 === ""?"-1":intval($n6);
        $n7 = $n7 === ""?"-1":intval($n7);
        $n8 = $n8 === ""?"-1":intval($n8);
        $n9 = $n9 === ""?"-1":intval($n9);
        $n10 = $n10 === ""?"-1":intval($n10);
        $updateData = array ( );
        $updateData = $MyLotto_3d->calOpenNum($n3 , $n2 , $n1 , $n4 , $n5 , $n6 , $n7 , $n8 , $n9 , $n10);
        $updateData['round'] = $round;
        $updateData['open'] = $open;
        if ( $gametype == 24 )
        {
            $updateData['n10'] = $n10;
            $updateData['n9'] = $n9;
        }
        if ( $Show8NFlag )
        {
            $updateData['n8'] = $n8;
            $updateData['n7'] = $n7;
            $updateData['n6'] = $n6;
        }
		if ( $Show5NFlag ){
        	$updateData['n5'] = $n5;
        	$updateData['n4'] = $n4;
		}
        $updateData['n3'] = $n3;
        $updateData['n2'] = $n2;
        $updateData['n1'] = $n1;
        $updateData['openbet'] = "{$openbet} {$openbetHours}:{$openbetMin}:00";
        $updateData['startbet'] = "{$openbet} {$startbetHours}:{$startbetMin}:00";
        $updateData['stopbet'] = "{$openbet} {$stopbetHours}:{$stopbetMin}:00";
        if ( $openbetHours.$openbetMin < $startbetHours.$startbetMin )
        {
            $updateData['startbet'] = date("Y-m-d H:i:s" , strtotime($updateData['startbet']) - 86400);
        }
        if ( $openbetHours.$openbetMin < $stopbetHours.$stopbetMin )
        {
            $updateData['stopbet'] = date("Y-m-d H:i:s" , strtotime($updateData['stopbet']) - 86400);
        }
        $breakFlag = false;
        switch ( $cmd )
        {
            case "add" :
                $openbetChkInt = strtotime($updateData['startbet']);
                if ( $addOnlyNowRound && time() < $openbetChkInt )
                {
                    continue;
                }
                if ( $MyLotto_3d->checkRoundOpenBet3S($updateData['openbet']) )
                {
                    continue;
                }
                if ( $cnyDateSInt <= $openbetChkInt && $openbetChkInt <= $cnyDateEInt )
                {
                    continue;
                }
                if ( $MyLotto_3d->checkRoundOpen3S($round , $open) )
                {
                    diemsg("{$tblName}资料输入错误" , "报表日期({$open})与期数({$round})已存在。" , $reUrl);
                }
                if ( $lotto_id = $MyLotto_3d->add($updateData) )
                {
                    $MyLotto_3d->copyRateZeroToN($lotto_id);
                    $openTempArr = explode("-" , $open);
                    if ( ! $MyLotto_3d->createTblBettotal($openTempArr[0].$openTempArr[1].$openTempArr[2]) )
                    {
                        diemsg("产生 bettotal_X_".$openTempArr[0].$openTempArr[1].$openTempArr[2]." 资料表时失败");
                    }
                    if ( intval(getvar("addOnlyOneRound")) == 1 )
                    {
                        $breakFlag = true;
                    }
                }
                else
                {
                    diemsg("{$tblName}新增失败" , "新增{$tblName}期数资料时发生问题" , $reUrl);
                }
                break;
            case "edit" :
                $id = intval(getvar("id"));
                if ( empty($id) )
                {
                    diemsg("{$tblName}资料输入错误" , "错误的ID值");
                }
                $id = intval($id);
                $rowChk = $MyLotto_3d->getDataById($id);
                if ( $rowChk === false )
                {
                    diemsg("{$tblName}资料输入错误" , "错误的ID值2");
                }
                $upFlag = true;
                if ( $curruser['account'] != G_SUPERACCOUNT && $curruser['id'] != 1 )
                {
                    switch ( $g_gametype_3d[$gametype]['type'] )
                    {
                        case 3 :
                            if ( $gametype == 24 )
                            {
                                $chkNumArr = array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 );
                            }
                            else
                            {
                                if ( $g_gametype_3d[$gametype]['en'] == "5h" )
                                {
                                    $chkNumArr = array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 );
                                }
                                else
                                {
                                    $chkNumArr = array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 );
                                }
                            }
                            break;
                        default :
                            $chkNumArr = array ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 );
                            break;
                    }
                    if ( in_array($rowChk['n3'] , $chkNumArr) && in_array($rowChk['n2'] , $chkNumArr) && in_array($rowChk['n1'] , $chkNumArr) )
                    {
                        $upFlag = false;
                        diemsg("{$tblName}目前不可更改资料" , "更新失败" , "op.php?op=admin&fp=history_3d&gametype={$gametype}");
                    }
                }
                if ( $upFlag )
                {	
                    $MyLotto_3d->update($updateData , $id);
                    if ( $updateData['open'] == "0000-00-00" )
                    {
                        header("location:op.php?op=admin&fp=history_3d&gametype={$gametype}");
                        exit();
                    }
                    if ( $chkGametype == 3 && ( $n5 == 0 - 1 && $n4 == 0 - 1 && $n3 == 0 - 1 && $n2 == 0 - 1 && $n1 == 0 - 1 ) )
                    {
                        include( "class_5h/class.lotto5h.php" );
                        $ClassLotto3D = new lotto5h($gametype);
                        $ClassLotto3D->ClearBetData($id);
                    }
                    else if ( $chkGametype != 3 && ( $n3 == 0 - 1 && $n2 == 0 - 1 && $n1 == 0 - 1 ) )
                    {
                        include( "class_3d/class.lotto3d.php" );
                        $ClassLotto3D = new lotto3d($gametype);
                        $ClassLotto3D->ClearBetData($id);
                    }
                    $editAgainFlag = true;
                    include_once( "admin/setOpenList.php" );
                    setOpenList($tbl);
                }
                break;
        }
        if ( $breakFlag )
        {
            break;
        }
    }
    if ( $cmd == "add" )
    {
        header("location:op.php?op=admin&fp=history_3d&gametype={$gametype}");
        exit();
    }
}
$round = "";
$open = "";
$n8 = "-1";
$n7 = "-1";
$n6 = "-1";
$n5 = "-1";
$n4 = "-1";
$n3 = "-1";
$n2 = "-1";
$n1 = "-1";
$tr01 = "";
$addOnlyOneRoundStr = "";
switch ( $cmd )
{
    case "edit" :
        $showQuick = false;
        $id = getvar("id");
        if ( empty($id) )
        {
            diemsg("{$tblName}资料输入错误" , "错误的ID值" , $reUrl);
        }
        $id = intval($id);
        $row = $MyLotto_3d->getDataById($id);
        $round = $row['round'];
        $open = $row['open'];
        if ( $gametype == 24 )
        {
            $n10 = $row['n1'];
            $n9 = $row['n2'];
            $n8 = $row['n3'];
            $n7 = $row['n4'];
            $n6 = $row['n5'];
            $n5 = $row['n6'];
            $n4 = $row['n7'];
            $n3 = $row['n8'];
            $n2 = $row['n9'];
            $n1 = $row['n10'];
        }
        else if ( $Show8NFlag )
        {
            $n8 = $row['n1'];
            $n7 = $row['n2'];
            $n6 = $row['n3'];
            $n5 = $row['n4'];
            $n4 = $row['n5'];
            $n3 = $row['n6'];
            $n2 = $row['n7'];
            $n1 = $row['n8'];
        }
        else if ( $chkGametype == 3 )
        {
            $n5 = $row['n1'];
            $n4 = $row['n2'];
            $n3 = $row['n3'];
            $n2 = $row['n4'];
            $n1 = $row['n5'];
        }
        else
        {
            $n5 = $row['n5'];
            $n4 = $row['n4'];
            $n3 = $row['n3'];
            $n2 = $row['n2'];
            $n1 = $row['n1'];
        }
        $openbet = $row['openbet'];
        $startbet = $row['startbet'];
        $stopbet = $row['stopbet'];
        $tempArr = explode(" " , $openbet);
        $tempHMArr = explode(":" , $tempArr[1]);
        $openDate = $tempArr[0];
        $openHours = $tempHMArr[0];
        $openMin = $tempHMArr[1];
        $tempArr = explode(" " , $stopbet);
        $tempHMArr = explode(":" , $tempArr[1]);
        $closeHours = $tempHMArr[0];
        $closeMin = $tempHMArr[1];
        $tempArr = explode(" " , $startbet);
        $tempHMArr = explode(":" , $tempArr[1]);
        $startHours = $tempHMArr[0];
        $startMin = $tempHMArr[1];
        $editFlag = false;
        $todays = date("Y-m-d");
        switch ( $gametype )
        {
            case 12 :
                if ( date("Hi") < "0210" )
                {
                    $paperDay = date("Y-m-d" , strtotime("-1 day"));
                }
                else
                {
                    $paperDay = $todays;
                }
                break;
            case 14 :
                if ( date("Hi") < "0210" )
                {
                    $paperDay = date("Y-m-d" , strtotime("-1 day"));
                }
                else
                {
                    $paperDay = $todays;
                }
                break;
            default :
                $paperDay = $todays;
                break;
        }
        $openTempStr = "<td>{$open}<input type=\"hidden\" name=\"open\" value=\"{$open}\" /></td>";
        if ( $curruser['account'] == G_SUPERACCOUNT && $curruser['acl'] == 255 )
        {
            $openTempStr = "<td><input type=\"text\" size=\"10\" name=\"open\" value=\"{$open}\" id=\"newPaperDate\" /><a href=\"#\" onclick=\"javascript:showCalendarById('newPaperDate')\"><img align=absmiddle src=\"class/calendar/calendar.png\"  border=0 alt=\"\"></a></td>";
            $editFlag = true;
        }
        else if ( ! $MyLotto_3d->checkOpen($n3 , $n2 , $n1 , $n4 , $n5 , $n6 , $n7 , $n8) )
        {
            $editFlag = true;
        }
        else if ( $paperDay == $open )
        {
            $editFlag = true;
        }
        else if ( $editAgainFlag )
        {
            $editFlag = true;
        }
        else
        {
            $editFlag = false;
        }
        if ( $editFlag )
        {
            $editStrDis = "";
        }
        else
        {
            $editStrDis = "disabled";
        }
        $list3s = "<tr class=\"row1\">".( "<td>1</td>" ).$openTempStr."<td><input type=\"text\" size=\"12\" name=\"round[1]\" value=\"{$round}\" {$editStrDis} /></td>"."<td><input type=\"text\" size=\"10\" readonly=\"readonly\" name=\"openbet[1]\" value=\"{$openDate}\" {$editStrDis} /></td>"."<td><input type=\"text\" size=\"1\" name=\"startbetHours[1]\" value=\"{$startHours}\" maxlength=\"2\" class=\"iptTimeBlue iptTimeH\" {$editStrDis} />：<input type=\"text\" size=\"2\" name=\"startbetMin[1]\" value=\"{$startMin}\" maxlength=\"2\" class=\"iptTimeBlue iptTimeM\" {$editStrDis} /></td>"."<td><input type=\"text\" size=\"1\" name=\"stopbetHours[1]\" value=\"{$closeHours}\" maxlength=\"2\" class=\"iptTimeRed iptTimeH\" {$editStrDis} />：<input type=\"text\" size=\"2\" name=\"stopbetMin[1]\" value=\"{$closeMin}\" maxlength=\"2\" class=\"iptTimeRed iptTimeM\" {$editStrDis} /></td>"."<td><input type=\"text\" size=\"1\"  readonly=\"readonly\" name=\"openbetHours[1]\" value=\"{$openHours}\" maxlength=\"2\" class=\"iptTime iptTimeH\" {$editStrDis} />：<input type=\"text\" size=\"2\" name=\"openbetMin[1]\"  readonly=\"readonly\" value=\"{$openMin}\" maxlength=\"2\" class=\"iptTime iptTimeM\" {$editStrDis} /></td>";
        if ( $gametype == 24 )
        {
            $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n10[1]\" value=\"{$n10}\" {$editStrDis} maxlength=\"2\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n9[1]\" value=\"{$n9}\" {$editStrDis} maxlength=\"2\" /></td>";
        }
        if ( $Show8NFlag )
        {
            $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n8[1]\" value=\"{$n8}\" {$editStrDis} maxlength=\"2\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n7[1]\" value=\"{$n7}\" {$editStrDis} maxlength=\"2\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n6[1]\" value=\"{$n6}\" {$editStrDis} maxlength=\"2\" /></td>";
        }
        if ( $Show5NFlag )
        {
            $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n5[1]\" value=\"{$n5}\" {$editStrDis} maxlength=\"2\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n4[1]\" value=\"{$n4}\" {$editStrDis} maxlength=\"2\" /></td>";
        }
        $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n3[1]\" value=\"{$n3}\" {$editStrDis} maxlength=\"2\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n2[1]\" value=\"{$n2}\" {$editStrDis} maxlength=\"2\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n1[1]\" value=\"{$n1}\" {$editStrDis} maxlength=\"2\" /></td>"."</tr>";
        $btnDisCalc = $editStrDis;
        $btnDisStopPlay = $editStrDis;
        $btnSubDis = $editStrDis;
        $btnResetDis = $editStrDis;
        if ( $n3 == 0 - 1 || $n2 == 0 - 1 || $n1 == 0 - 1 || $row['calcbet'] == "1" )
        {
            $btnDisCalc = "disabled=\"disabled\"";
        }
        if ( $Show5NFlag && ( $n5 == 0 - 1 || $n4 == 0 - 1 ) )
        {
            $btnDisCalc = "disabled=\"disabled\"";
        }
        if ( $Show8NFlag && ( $n8 == 0 - 1 || $n7 == 0 - 1 || $n6 == 0 - 1 ) )
        {
            $btnDisCalc = "disabled=\"disabled\"";
        }
        $now = systime();
        if ( strtotime($startbet) < $now && $now < strtotime($stopbet) )
        {
            $btnDisStopPlay = "";
        }
        else
        {
            $btnDisStopPlay = "disabled=\"disabled\"";
        }
        $btnUpdateGruop = "<input {$btnDisStopPlay} type=button value=\"立刻停止下注\" id=\"btnStopBetNow\" onclick=\"this.disbled=disabled;\">";
        $btnUpdateGruop .= "<input type=\"button\" value=\"颁奖\" {$btnDisCalc} id=\"btnCalc\" />";
        if ( $curruser['account'] == G_SUPERACCOUNT && $curruser['acl'] == 255 )
        {
            $btnUpdateGruop .= "<input type=\"button\" value=\"颁奖按钮解除\" id=\"btnOpenDisCalc\" />";
            $jsCode = "<script>";
            $jsCode .= "$(function(){";
            $jsCode .= "  $(\"input:button#btnOpenDisCalc\").click(function(){";
            $jsCode .= "    $.get(\"?op=admin&fp=xmlSetConf_3d&cmd=openDisCalc&id=".$id."&gametype=".$gametype."\", function(data){";
            $jsCode .= "      if(data == \"true\"){";
            $jsCode .= "        location.replace(\"op.php?op=admin&fp=lotto_3s&cmd=edit&gametype=".$gametype."&id=".$id."\");";
            $jsCode .= "      }else{";
            $jsCode .= "        alert(\"error\");";
            $jsCode .= "      }";
            $jsCode .= "    });";
            $jsCode .= "  });";
            $jsCode .= "});";
            $jsCode .= "</script>";
        }
        break;
    case "add" :
        $showQuick = true;
        $btnSubDis = "";
        $btnResetDis = "";
        $btnUpdateGruop = "";
        $tr01 = "<br /><br /><span style='font-weight:bold;'>※ 报表日期若有异动，请点选「计算日期」更新开奖日期 ※</span>";
        if ( $round = $MyLotto_3d->getLotto_3d_id() )
        {
            $round = $round;
        }
        else
        {
            $round = 0;
        }
        $open = date("Y-m-d");
        $showListArr = $MyLotto_3d->getOpenInfo($gametype , $round);
        $list3s = "";
        $tempClass = 1;
        $tempI = 0;
        $openTimeInt = 0;
        $startTimeInt = 0;
        $cutI = 0;
        foreach ( $showListArr as $key => $showListVal )
        {
            $openTimeInt = $openTimeInt == 0?strtotime($open." ".$showListVal['start']):$openTimeInt;
            $startTimeInt = $startTimeInt == 0?$openTimeInt - $showListVal['next']:$startTimeInt;
            $i = 0;
            while ( $i < $showListVal['round'] )
            {
 ++ $tempI;
                $tempClass = $tempI % 2 + 1;
                $startTimeInt = $startTimeInt + $showListVal['startPre'];
                $openDate = date("Y-m-d" , $openTimeInt);
                $openHours = date("H" , $openTimeInt);
                $openMin = date("i" , $openTimeInt);
                $closeTimeInt = $openTimeInt - $showListVal['preClose'];
                $closeHours = date("H" , $closeTimeInt);
                $closeMin = date("i" , $closeTimeInt);
                $startHours = date("H" , $startTimeInt);
                $startMin = date("i" , $startTimeInt);
				
                if ( $startHours.$startMin == "0000")
                {
                    $cutI = $gametype == 14?0:120;
                    $showListVal['preStr'] = $gametype == 14?date("md" , strtotime("+0 day")):date("md" , strtotime("+1 day"));
                }
				else if ($startHours.$startMin == "2353"  && $gametype==23)
                {
                    $cutI = 97;
                    $showListVal['preStr'] = date("Ymd" , $startTimeInt+24*3600).'-';
                }
                if ( $gametype == 24 )
                {
                    if ( $tempI == 1 )
                    {
                        $roundStr = $showListVal['preStr'];
                    }
                    else
                    {
                        $roundStr = $roundStr + 1;
                    }
                }
                else
                {
                    $roundStr = $showListVal['preStr'].str_pad($showListVal['sn'] + $tempI - $cutI , $showListVal['len'] , "0" , STR_PAD_LEFT);
                }
                echo "<item qs=\"{$roundStr}\" time=\"{$openHours}:{$openMin}\"></item>\r\n";
                if ( $tempI == 1 )
                {
                    $openStr = "<input type=\"text\" size=\"10\" name=\"open\" value=\"{$open}\" id=\"newPaperDate\" /><a href=\"#\" onclick=\"javascript:showCalendarById('newPaperDate')\"><img align=absmiddle src=\"class/calendar/calendar.png\"  border=0 alt=\"\"></a><input type=\"button\" value=\"计算日期\" id=\"btnNewPaperDate\" />";
                }
                else
                {
                    $openStr = "--";
                }
                $list3s .= "<tr class=\"row{$tempClass}\">\r\n  <td>{$tempI}</td>\r\n  <td>{$openStr}</td>\r\n  <td><input type=\"text\" size=\"12\" name=\"round[{$tempI}]\" value=\"{$roundStr}\" class=\"inpRound\" /></td>\r\n  <td><input type=\"text\" size=\"10\"  readonly=\"readonly\" name=\"openbet[{$tempI}]\" class=\"inpOpenbet\" value=\"{$openDate}\" /></td>\r\n  <td><input type=\"text\" size=\"1\" name=\"startbetHours[{$tempI}]\" value=\"{$startHours}\" maxlength=\"2\" class=\"iptTimeBlue iptTimeH\" />：<input type=\"text\" size=\"2\" name=\"startbetMin[{$tempI}]\" value=\"{$startMin}\" maxlength=\"2\" class=\"iptTimeBlue iptTimeM\" /></td>\r\n  <td><input type=\"text\" size=\"1\" name=\"stopbetHours[{$tempI}]\" value=\"{$closeHours}\" maxlength=\"2\" class=\"iptTimeRed iptTimeH\" />：<input type=\"text\" size=\"2\" name=\"stopbetMin[{$tempI}]\" value=\"{$closeMin}\" maxlength=\"2\" class=\"iptTimeRed iptTimeM\" /></td>\r\n  <td><input type=\"text\" size=\"1\"  readonly=\"readonly\" name=\"openbetHours[{$tempI}]\" value=\"{$openHours}\" maxlength=\"2\" class=\"iptTime iptTimeH\" />：<input type=\"text\" size=\"2\"  readonly=\"readonly\" name=\"openbetMin[{$tempI}]\" value=\"{$openMin}\" maxlength=\"2\" class=\"iptTime iptTimeM\" /></td>\r\n  ";
                if ( $gametype == 24 )
                {
                    $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n10[{$tempI}]\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n9[{$tempI}]\" /></td>";
                }
                if ( $Show8NFlag )
                {
                    $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n8[{$tempI}]\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n7[{$tempI}]\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n6[{$tempI}]\" /></td>";
                }
                if ( $Show5NFlag )
                {
                    $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n5[{$tempI}]\" /></td>"."<td><input type=\"text\" size=\"1\" name=\"n4[{$tempI}]\" /></td>";
                }
                $list3s .= "<td><input type=\"text\" size=\"1\" name=\"n3[{$tempI}]\" /></td>\r\n  <td><input type=\"text\" size=\"1\" name=\"n2[{$tempI}]\" /></td>\r\n  <td><input type=\"text\" size=\"1\" name=\"n1[{$tempI}]\" /></td>\r\n  </tr>\r\n  ";
                $startTimeInt = $openTimeInt;
                $openTimeInt += $showListVal['next'];
                ++ $i;
            }
            unset($showListArr[$key]);
            $openTimeInt = 0;
        }
        $addOnlyOneRoundStr = "<label style=\"padding-right:20px;\"><input name=\"addOnlyOneRound\" type=\"checkbox\" value=\"1\" />仅新增一期</label>";
        $addOnlyOneRoundStr .= "<label style=\"padding-right:20px;\" title=\"可撘配自动开盘使用\"><input name=\"addOnlyNowRound\" type=\"checkbox\" value=\"1\" />新增至目前开盘期数</label>";
        break;
}
$openFlag = $MyLotto_3d->checkOpen($n3 , $n2 , $n1 , $n4 , $n5);
switch ( $gametype )
{
    case 10 :
        $showNNPaper = "false";
        $thisDayLt = "23";
        break;
    case 11 :
        $showNNPaper = "true";
        $thisDayLt = "84";
        break;
    case 12 :
        $showNNPaper = "true";
        $thisDayLt = "96";
        break;
    case 13 :
        $showNNPaper = "true";
        $thisDayLt = "84";
        break;
    case 14 :
        $showNNPaper = "true";
        $thisDayLt = "71";
        break;
    case 15 :
        $showNNPaper = "true";
        $thisDayLt = "88";
        break;
    case 20 :
        $showNNPaper = "false";
        $thisDayLt = "50";
        break;
    case 21 :
        $showNNPaper = "true";
        $thisDayLt = "84";
        break;
    case 22 :
        $showNNPaper = "true";
        $thisDayLt = "84";
        break;
    case 23 :
        $showNNPaper = "true";
        $thisDayLt = "84";
        break;
    case 24 :
        $showNNPaper = "false";
        $thisDayLt = "179";
        break;
	case 25 :
        $showNNPaper = "true";
        $thisDayLt = "82";
        break;
	case 26 :
        $showNNPaper = "true";
        $thisDayLt = "82";
        break;
    default :
        exit("error gametype in showNNP");
        break;
}
echo title("{$tblName} 新增期数管理" , "<a href=\"op.php?op=admin&fp=history_3d&gametype={$gametype}\">列表</a>" , 800);
switch ( $g_gametype_3d[$gametype]['type'] )
{
    case 2 :
        if ( $Show5NFlag )
        {
            $thShow5N = "<th>万</th><th>千</th><th>佰</th><th>拾</th><th>个</th>";
            $trColspan = "12";
        }
        else
        {
            $thShow5N = "<th>佰</th><th>拾</th><th>个</th>";
            $trColspan = "10";
        }
        break;
    case 3 :
        if ( $gametype == 20 )
        {
            $thShow5N = "<th>平一</th><th>平二</th><th>平三</th><th>平四</th><th>特码</th>";
            $trColspan = "12";
        }
        else if ( $gametype == 24 )
        {
            $thShow5N = "<th>第一球</th><th>第二球</th><th>第三球</th><th>第四球</th><th>第五球</th><th>第六球</th><th>第七球</th><th>第八球</th><th>第九球</th><th>第十球</th>";
            $trColspan = "17";
        }
        else
        {
            $thShow5N = "<th>第一球</th><th>第二球</th><th>第三球</th><th>第四球</th><th>第五球</th><th>第六球</th><th>第七球</th><th>第八球</th>";
            $trColspan = "15";
        }
        break;
	 case 4 :
         $thShow5N = "<th>一</th><th>二</th><th>三</th>";
         $trColspan = "10";
        break;
    default :
        exit("error gametype in opendate");
        break;
}
$tpl->set(array ( "cmd" => $cmd , "round" => $round , "open" => $open , "n5" => $n5 , "n4" => $n4 , "n3" => $n3 , "n2" => $n2 , "n1" => $n1 , "id" => $id , "gametype" => $gametype , "list3s" => $list3s , "btnUpdateGruop" => $btnUpdateGruop , "btnSubDis" => $btnSubDis , "btnResetDis" => $btnResetDis , "editType" => "false" , "tr01" => $tr01 , "showNNPaper" => $showNNPaper , "thisDayLt" => $thisDayLt , "thisDayGt" => $thisDayLt - 1 , "addOnlyOneRound" => $addOnlyOneRoundStr , "thShow5N" => $thShow5N , "trColspan" => $trColspan ));
$tpl->load("main" , "lotto_3s.htm");
$ui->set("jslink" , $jsCode);
$ui->header();
if ( $showQuick && $gametype == 20 )
{
    $tpl->load("lotto_3s_round" , "lotto_5h_round.htm");
    $tpl->show("lotto_3s_round");
}
if ( $showQuick && $gametype == 24 )
{
    $tpl->load("lotto_3s_round" , "lotto_10h_round.htm");
    $tpl->show("lotto_3s_round");
}
echo "<br />";
$ui->load("calendar_js" , "calendar_js.htm");
$ui->show("calendar_js");
$tpl->show("main");
$ui->footer();